window.workspace = function(){
	var response  = <?#$respons?>;
	var store, grid, win, form, sm;
	var sid = {'keyword':Ext.id()};
	function addForm(rows){
		if(!win) {
		    form = new Ext.form.FormPanel({
				frame		: true,
				border		: false,
				bodyStyle	: 'padding:8px;',
		        labelWidth	: 128,
		        fileUpload  : true,
		        labelAlign  : 'right',
		    	defaults	: {
		    		xtype	  : 'textfield'
		    	},
		    	items		: [{
					xtype		: 'hidden',
					name		: 'id',
					value		: 0
				},{
					xtype		: 'textfield',
					fieldLabel	: '标签名称[Name]',
					width		: 160,
					name		: 'name',
					maxLength   : 63,
					allowBlank	: false
				},{
					xtype		: 'numberfield',
					fieldLabel	: '排序[Rank]',
					width		: 120,
					name		: 'rank',
					allowBlank	: false
				},{
					xtype		: 'textfield',
					inputType 	: 'file', 
			 		fieldLabel	: '默认图标[DefaultIcon]',
					name		: 'Filedata'
				},{
					xtype		: 'textfield',
					inputType 	: 'file', 
			 		fieldLabel	: '切换图标[HoverIcon]',
					name		: 'Filethumb'
				},{
		    		xtype		: 'combo',
		            store		: new Ext.data.ArrayStore({
			        	fields: ['id','name'],
			        	data: main.cv2Array(response.status)
			    	}),
					displayField	: 'name',
					valueField		: 'id',
					mode			: 'local',
					emptyText		: 'selected...',
		            fieldLabel		: '状态[Status]',
		            width			: 120,
		            allowBlank		: false,
					triggerAction	: 'all',
					hiddenName		: 'status',
		            name			: 'status'
		        },{
		    		xtype		: 'combo',
		            store		: new Ext.data.ArrayStore({
			        	fields: ['id','name'],
			        	data: main.cv2Array(response.yes2no)
			    	}),
					displayField	: 'name',
					valueField		: 'id',
					mode			: 'local',
					emptyText		: 'selected...',
		            fieldLabel		: '是否展示[IsShow]',
		            width			: 120,
		            allowBlank		: false,
					triggerAction	: 'all',
					hiddenName		: 'isshow',
		            name			: 'isshow'
		        },{
					xtype		: 'textarea',
					fieldLabel	: '描述[Desc]',
					width		: 220,
					name		: 'desc'
				}]
			});
			win = new Ext.Window({
				title	: 'Add Tag',
				iconCls	: 'icon-add',	
				width	: 420,
				items	: [form],
				closeAction : 'hide',
				bbar 	: {
					xtype		: 'toolbar',
					buttonAlign	: 'right',
					items		: [{
						text	: '保存[Save]', 
						iconCls	: 'icon-save',
						url		: '/admin/live/config/tags/dosave.html',
						handler	: function(){
						if(!form.getForm().isValid())
		        			return;
		        		form.getForm().submit({
		        			waitMsg		: GLang['30017'],
							waitTitle 	: GLang['30003'],
			        		clientValidation: true,
			        		url		: '/admin/live/config/tags/dosave.html',
				        	success	: function(form, action) {
				        		store.reload();
				        		win.hide();
							},
							failure	: main.submitFailure
				    	});
					}}]
				}
			});
		}
		var id = Ext.isObject(rows)? rows.id:0;
		win.setTitle((id > 0)? '编辑[Edit]':'新增[Add]');
		win.setIconClass((id > 0)? 'icon-edit':'icon-add');
		win.show();
		if(id < 1) {
			form.getForm().reset();
		} else {
			form.getForm().loadRecord(rows);
		}
	};
	store = new Ext.data.JsonStore({
	    autoDestroy	: true,
	    url			: '/admin/live/config/tags/dolist.html',
	    remoteSort	: true,
	    sortInfo	: {
	            field		: 'id',
	            direction	: 'DESC'
		},
		baseParams	: {
			start	: 0,
			limit	: main.pageSize
		},
		autoLoad		: true,
	    root			: 'dataset',
	 	totalProperty	: 'total',
	    fields			: ['id', 'name', 'issys', 'icon',
	         'count', 'thumb', 'isshow', 'desc', 'rank', 'status', 'stime']
	});
	sm   = new Ext.grid.CheckboxSelectionModel();
 	grid = {
		xtype		: 'grid',
		title		: response.title,
	    store		: store,
		region		: 'center', 
	    columns		: [
	        sm,
			{header: '编号[ID]', width:60, sortable:true, dataIndex:'id'},
			{header: '标签名称[Name]', width:120, dataIndex:'name'},
			{header: '默认图标[DefaultIcon]', width:80, dataIndex:'icon', renderer:function(v){
				if(/\.(png|jpg|jpeg|gif|bmp)$/i.test(v)) {
					 return '<img src="'+Ext.STATIC_URL+v+'" height="25" />';
				 }
				 return '';
			}},
			{header: '切换图标[HoverIcon]', width:80, dataIndex:'thumb', renderer:function(v){
				if(/\.(png|jpg|jpeg|gif|bmp)$/i.test(v)) {
					 return '<img src="'+Ext.STATIC_URL+v+'" height="25" />';
				 }
				 return '';
			}},
			{header: '描述[Desc]', width:240, dataIndex:'desc'},
			{header: '排序[Rank]', width:80, sortable:true, dataIndex:'rank'},
			{header: '状态[Status]', width:80, sortable:true, dataIndex:'status', renderer:function(v){
				return response.status[v];
			}},
			{header: '是否展示[IsShow]', width:80, sortable:true, dataIndex:'isshow', renderer:function(v){
				return response.yes2no[v];
			}},
			{header: '分类统计[Stats]', width:80, sortable:true, dataIndex:'count'},
			{header: '更新时间[LastTime]', width:100, sortable:true, dataIndex:'stime'}
		],
	    viewConfig	: {
	        forceFit	 : true,
	        scrollOffset : 0
	    },
	    listeners	: {
	    	'destroy':function(){
    			win && win.close();
    		},'rowdblclick':function(grid, index, e){
		    	var data = grid.store.getAt(index).copy();
		    	addForm(data);
		    }
    	},
	    sm			: sm,
	    stripeRows	: true,
	    tbar		: [{
			text	: '刷新[Reload]',
			iconCls	: 'icon-refresh',
			handler : function(){
				store.reload(); 
			}
	    },'-',{
			text	: '添加[Add]',
			iconCls	: 'icon-add',
			url		: '/admin/live/config/tags/dosave.html',
			handler : function() {
				addForm(0);
			}
		},'-',{
			text	: '删除[Del]',
			iconCls	: 'icon-delete',
			url		: '/admin/live/config/tags/dodelete.html',
			handler : function() {
				var rcs = grid.sm.getSelections();
				if(Ext.isEmpty(rcs)) {
					Ext.Msg.alert(GLang['30003'], GLang['30020']);
					return;
				}
				var ids= [];
				Ext.each(rcs, function(item){
					ids.push(item.get('id'));
				});
				Ext.Msg.confirm(GLang['30003'], GLang['30025'], function(btn){
					if(btn=="yes") {
						Ext.Ajax.request({
							url		: '/admin/live/config/tags/dodelete.html',
							params	: {'ids':ids.join(',')},
							success : function(resp, req){
								var data = Ext.decode(resp.responseText);
								if(data.code == 0) {
									store.reload(); 
								} else {
									Ext.Msg.alert(GLang['30003'], data.msg);
								}
							}
						});
					}
				});
			}
		},'-','标签名称[Name]:',{
			xtype       : 'textfield',
			id	    	: sid.keyword,
			width	    : 80
		},'-',{
			text			: '检索',
			iconCls			: 'icon-search',
			handler: function() {
				store.baseParams.keyword = Ext.getCmp(sid.keyword).getValue();
				store.reload(); 
			}
		}],
		bbar		: new Ext.PagingToolbar({
			pageSize	: main.pageSize,
			store		: store,
			displayInfo	: true
		})
	};
	return grid;
}();